package com.dai.spec.gxk.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dai.spec.common.core.domain.AjaxResult;
import com.dai.spec.common.enums.ProfessionalTitleType;
import com.dai.spec.common.utils.SecurityUtils;
import com.dai.spec.gxk.domain.Teacher;
import com.dai.spec.gxk.mapper.TeacherMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 教师信息 业务处理
 *
 * @author daikangle
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/system/teacher/profile")
public class TeacherInfoController {

    private TeacherMapper teacherMapper;

    public TeacherInfoController(TeacherMapper teacherMapper) {
        this.teacherMapper = teacherMapper;
    }

    /**
     * 教师信息
     */
    @GetMapping
    public AjaxResult profile() {

        String jobNumber = SecurityUtils.getLoginUser().getUsername();
        LambdaQueryWrapper<Teacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Teacher::getJobNumber, jobNumber);
        Teacher teacher = teacherMapper.selectOne(queryWrapper);
        AjaxResult ajax = AjaxResult.success(teacher);
        if (teacher != null) {
            ajax.put("jobNumber", jobNumber);
            ajax.put("professionalTitle", ProfessionalTitleType.getValueByCode(teacher.getProfessionalTitle()));
            ajax.put("age", teacher.getAge());
        }

        return ajax;

    }
}
